from 代理.core.capture.base_capture import BASER_CAPTURE
from 代理.untils.user_agent import get_request_headers
import requests

class YUNDAILI(BASER_CAPTURE):
    urls=['http://www.ip3366.net/?stype=1&page={}'.format(i) for i in range(1, 11)]
    group_xpath='//*[@id="list"]/table/tbody/tr'
    detail_xpath = {
        'ip': './td[1]/text()',
        'port': './td[2]/text()',
        'area': './td[6]/text()'
    }
    def get_page_from_url(self,url):
        response=requests.get(url,headers=get_request_headers())
        response.encoding='gb2312'
        return response.text

class KUAIDAILI(BASER_CAPTURE):
    urls=['https://free.kuaidaili.com/free/inha/{}/'.format(i) for i in range(1, 4)]
    group_xpath='//*[@id="list"]/table/tbody/tr'
    detail_xpath = {
        'ip': './td[1]/text()',
        'port': './td[2]/text()',
        'area': './td[5]/text()'
    }
class PLUSDAILI(BASER_CAPTURE):
    urls=['https://list.proxylistplus.com/Fresh-HTTP-Proxy-List-{}'.format(i) for i in range(1, 7)]
    group_xpath='//*[@id="page"]/table[2]/tr[position()>2]'
    detail_xpath = {
        'ip': './td[2]/text()',
        'port': './td[3]/text()',
        'area': './td[5]/text()'
    }
class NUMBERDAILI(BASER_CAPTURE):
    urls = ['http://www.66ip.cn/{}.html'.format(i) for i in range(1, 6)]
    group_xpath = '//*[@id="main"]/div[1]/div[2]/div[1]/table/tr[position()>2]'
    detail_xpath = {
        'ip': './td[1]/text()',
        'port': './td[2]/text()',
        'area': './td[3]/text()'
    }
    def get_page_from_url(self,url):
        response = requests.get(url, headers=get_request_headers())
        response.encoding='gb2312'
        return response.text

if __name__ == '__main__':
    yun_spider = YUNDAILI()
    for proxy in yun_spider.get_proxies():
        print(proxy)
    # kuai_spider=KUAIDAILI()
    # for proxy in kuai_spider.get_proxies():
    #     print(proxy)
    # plus_spider = PLUSDAILI()
    # for proxy in plus_spider.get_proxies():
    #     print(proxy)
    # numbers_spider = NUMBERDAILI()
    # for proxy in numbers_spider.get_proxies():
    #     print(proxy)


